package fr.afcepf.atod21.data;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.ResourceBundle;
import java.util.logging.Logger;

import javax.sql.DataSource;

/**
 * DataSource pour se connecter a la BDD
 * 'organisme_formation'.
 * @author Stagiaire
 *
 */
public class Atod21DataSource implements DataSource {

    @Override
    public PrintWriter getLogWriter() throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void setLogWriter(PrintWriter paramOut) throws SQLException {
        // TODO Auto-generated method stub
    }

    @Override
    public void setLoginTimeout(int paramSeconds) throws SQLException {
        // TODO Auto-generated method stub
    }

    @Override
    public int getLoginTimeout() throws SQLException {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public <T> T unwrap(Class<T> paramIface) throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean isWrapperFor(Class<?> paramIface) throws SQLException {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public Connection getConnection() throws SQLException {
        Connection cnx = null;
        ResourceBundle rb = ResourceBundle.getBundle("fr.afcepf.atod21.ressources.db");
        try {
            Class.forName(rb.getString("jdbcDriver"));
            cnx = DriverManager.getConnection(
                    rb.getString("url"),
                    rb.getString("username"),
                    rb.getString("password"));
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
        return cnx;
    }

    @Override
    public Connection getConnection(String paramUsername, String paramPassword)
            throws SQLException {
        return null;
    }

}
